package com.zrrd.bufferedStream;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author WanJl
 * @version 1.0
 * @title BufferedOutputStreamDemo01
 * @description 字节缓冲输出流
 * @create 2024/5/25
 */
public class BufferedOutputStreamDemo01 {
    public static void main(String[] args) {
        //创建对象
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;

        try {
            //创建文件字节输出流对象，参数是文件路径，操作的是文件
            fos=new FileOutputStream("E:/users/abc.txt");//基础流
            //创建字节缓冲输出流对象，参数是字节输出流对象或其子类对象
            bos=new BufferedOutputStream(fos);//处理流

            //输出数据
            bos.write("hello World".getBytes());
            bos.write("hello Java".getBytes());


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            //释放资源的顺序
            try {
                bos.close();//缓存流-处理流
                fos.close();//输出流-基础流
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
